/*
 * @Author: ray
 * @Date:   2019-07-28 20:27:47
 * @Last Modified by:   ray
 * @Last Modified time: 2019-08-10 14:25:37
 */
import ZenUI from "@root/components/ZenUI/ZenUI";
REST.getCurrentProjectConfig = function() {
	return {
		// baseUrl: "http://192.168.2.221:8001"
		// baseUrl: "http://192.168.17.215:8032"
		// baseUrl: "https://m.rjmart.rj-info.com/api"
		// baseUrl: "https://m.test4.rj-info.com/api"
		baseUrl: ""
	};
};

REST.hookWhenGetResponse = function(res, fireErr) {
	// Uts.setCookie("SPAccrosToken", "");
	console.log(res);
	if (
		res &&
		res.response &&
		res.response.data &&
		res.response.data.code == "401"
	) {
		if (!Uts.contain($state.name, "/Login")) {
			$state.go({
				name: "/Login"
			});
		}
	}
	if (fireErr) {
		if (res.response && res.response.data && res.response.data.message) {
			// ZenUI.ST(res.response.data.message, 5);
		}
		if (
			(res && res.status == 401) ||
			(res && res.response && res.response.status == 401)
		) {
			if (!Uts.contain($state.name, "/Login")) {
				$state.go({
					name: "/Login"
				});
			}
		}
		// console.log("err:", res);
	}
};

Uts.removeState = function(stateName, value, notChangeState) {
	var str = "";
	var currentHash = location.hash;
	var newHash = "";
	let paramsObj = Uts.getParamsFormSearch(
		currentHash.substring(currentHash.indexOf("?"))
	);
	if (!paramsObj[stateName]) {
		return false;
	}
	let valueList = paramsObj[stateName].split(",");
	let newValueList = valueList.filter(function(data) {
		return data != value;
	});
	let STREXP = new RegExp("([\\?&])" + stateName + "=[^&]*");
	currentHash = currentHash.replace(
		STREXP,
		"$1" + stateName + "=" + newValueList.join(",")
	);
	if (notChangeState) {
		return currentHash;
	}
	Uts.repleaceState(null, null, currentHash);
};
